/**
 * 动态加载高德地图 api 函数
 * @param {String} key 高德地图的key
 */
export default function AMapLoader() {
  return new Promise(function (resolve, reject) {
    if (typeof window.AMap !== 'undefined') {
      resolve(window.AMap)
      return true
    }
    window.initAMap = function () {
      resolve(window.AMap)
    }
    let script = document.createElement('script')
    script.type = 'text/javascript'
    script.src = 'http://webapi.amap.com/maps?v=1.4.11&callback=initAMap&key=24a25f9b0a5cb6945ff9007792cc5cb2'
    script.onerror = reject
    document.head.appendChild(script)
  })
}